@extends("layout.admin")

@section("title")
    用户列表
@endsection

@section("content")
    {{--列表--}}
    <div class="layui-card-body">
        <form id="search-form">
            <input type="hidden" name="group_id" value="{{request('group_id')}}">
        </form>
        <div class="layui-inline">
            <div id="tags" style="width: 400px;"></div>
        </div>
        <div class="layui-inline layui-show-xs-block">
            <button class="layui-btn" lay-submit="" lay-filter="sreach" id="submit"><i class="layui-icon"></i>添加
            </button>
            <a class="layui-btn" onclick="window.location.href='{{ route("admin.usergroup.index") }}'">返回</a>
        </div>
    </div>
    <div class="layui-card-body ">
        <table lay-filter="table-hide" style="display: none"  lay-data="{height:'full-310', cellMinWidth: 80,toolbar: '#toolbar',defaultToolbar:['filter'],limit:{{$data['per_page']}}}">
            <thead>
            <tr>
                <th lay-data="{field:'id',width:80, fixed: 'left', unresize: true, sort: true}">编号</th>
                <th lay-data="{field:'group_name'}">分组名称</th>
                <th lay-data="{field:'name'}">名称</th>
                <th lay-data="{field:'type_text'}">类型</th>
                <th lay-data="{field:'number'}">人数</th>
                <th lay-data="{field:'created_at'}">创建时间</th>
                <th lay-data="{field:'updated_at'}">更新时间</th>
                <th lay-data="{field:'op',fixed: 'right', width:220, align:'center'}">操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach ($data['data'] as $vo)
                <tr>
                    <td>{{ $vo['id'] }}</td>
                    <td>{{ $vo['group_name'] }}</td>
                    <td>{{ $vo['name'] }}</td>
                    <td>{{ $vo['type_text'] }}</td>
                    <td>{{ $vo['number'] }}</td>
                    <td>{{ $vo['created_at'] }}</td>
                    <td>{{ $vo['updated_at'] }}</td>
                    <td data-field="controller">
                        @if(_can('admin.usergroup.destroy'))<a class="layui-btn layui-btn-xs layui-btn-danger" onclick="admin.tableDataDelete('{{ route("admin.usergroup.destroy.attach", ['id' => $vo['id']]) }}', this,'确认移除吗')">移除</a>@endif
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
        @include("layout.page")
    </div>
@endsection

@section('script')
    <script src="{{asset('layui/modules/xm-select.js')}}"></script>
    <script>
        var idx=-1;
        layui.use(['form', 'table', 'layer','xmSelect'], function () {
            var table = layui.table;
            var form = layui.form,xmSelect = layui.xmSelect;
            table.init("table-hide");
            var demo4 = xmSelect.render({
                el: '#tags',
                paging: true,
                pageSize: 5,
                filterable: true,
                pageEmptyShow: false,
                autoRow: true,
                template({ item }){
                    return item.name;
                },
                prop: {
                    name: 'showname',
                },
                data:{!! $list !!}
            })
            $("#submit").click(function(){
                var group_id = '{{request("group_id")}}'
                var value = demo4.getValue();
                $.post("{{route('admin.usergroup.create.attach')}}",{group_id:group_id,value:value,_token:'{{ csrf_token() }}'},function(data){
                    var icon = 5;
                    if(data.status > 0){
                        icon = 6;
                    }
                    layer.msg(data.message,{icon:icon},function(){
                        if (data.status > 0) {
                            window.location.reload();
                        }
                    })
                })
            });
            admin.paginate("{{ $data['total'] }}", "{{ $data['current_page'] }}", "{{ $data['per_page'] }}");
        });
    </script>
    <script src="{{asset('js/layCommon.js')}}"></script>
@endsection

